/**
 * Created by dukes on 2016/3/11.
 */
class GuildShop extends eui.Component{
    public constructor(){
        super();
        // this.skinName = "skins.scene.GuildShopSkin";
        // this.name = "guildShop";
        // this.frameItem = new FrameItem();
        // this.frameItem.callObj = this;
        // this.frameItem.callFun = this.update;
        // this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAdded, this );
        // this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoved, this);
    }
    // private frameItem:FrameItem;
    // private lastChipsRequestTime = 0;
    // private update(){
    //     if( this.fuck_tab.selectedIndex == 1){
    //         var gap:number = this.nextAutoRefreshTime - Model.SYSTIME;
    //         if( gap > 0){
    //             var timestr:string = GetTimeStr(gap,2,false);
    //             this.refresh_timer.text = timestr+"后自动刷新";
    //         }else{
    //             var now = Date.now();
    //             if( now - this.lastChipsRequestTime > 10000){
    //                 window["__chipses"]();
    //                 this.lastChipsRequestTime = now;
    //             }
    //         }

    //     }else{
    //         FrameMgr.getInstance().delController(this.name);
    //     }
    // }
    // private onSelectedTab(evt:eui.IndexChangeEvent){
    //     SoundMgr.getInstance().playEffect(SoundMgr.BTN);
    //     this.shop_container.removeAllElements();
    //     if( this.lastSelectItem)
    //         this.lastSelectItem.setState("normal");
    //     this.lastSelectItem = null;
    //     if( evt.newIndex == 0){
    //         this.shop_container.addChild(GuildMaterialShop.getInstance());
    //         GuildMaterialShop.getInstance().setType(1);
    //         if( this.lastSelectItem)
    //             this.updateShopItemRelated(this.lastSelectItem.curData);
    //         this.group_pet_material.visible = false;
    //     }else if( evt.newIndex == 1){
    //         this.shop_container.addChild(GuildMaterialShop.getInstance());
    //         GuildMaterialShop.getInstance().setType(2);
    //         this.group_pet_material.visible = true;
    //         this.group_lock.visible = this.group_unlock.visible = false;
    //         this.updateMaterialGroup();
    //     }
    // }

    // public onReturn(evt:egret.TouchEvent){
    //     SceneMgr.getInstance().switchScene(SceneMgr.SCENE_GUILD);
    // }

    // public onAdd(evt:egret.TouchEvent){
    //     var curCnt = parseInt(this.lab_unlock.text);
    //     curCnt++;
    //     this.lab_unlock.text = curCnt+"";
    //     this.lab_unlock_1.text = "消耗：贡献 " +this.lastSelectItem.curData.price*curCnt;
    // }
    // public onReduce(evt:egret.TouchEvent){
    //     var curCnt = parseInt(this.lab_unlock.text);
    //     curCnt--;
    //     if( curCnt < 0 )
    //         curCnt=0;
    //     this.lab_unlock.text = curCnt+"";
    //     this.lab_unlock_1.text = "消耗：贡献 " +this.lastSelectItem.curData.price*curCnt;
    // }
    // public onMax(evt:egret.TouchEvent){
    //     var data = this.lastSelectItem.curData;
    //     //var maxCnt = Math.floor(GuildMgr.getInstance().myMemberInfo.contribution/data.price);
    //     this.lab_unlock.text = "100";
    //     this.lab_unlock_1.text = "消耗：贡献 " + data.price*100;
    // }
    // public onBuy(evt:egret.TouchEvent){
    //     var cnt = parseInt(this.lab_unlock.text);
    //     if( cnt != 0)
    //         window["__buyGuildGoods"](this.lastSelectItem.curData.id,cnt);
    // }
    // public onRefresh(evt:egret.TouchEvent){
    //     window["__refreshMaterial"]();
    // }

    // private onAdded(evt:egret.Event){
    //     this.img_return.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onReturn, this);
    //     this.fuck_tab.addEventListener(eui.IndexChangeEvent.CHANGE, this.onSelectedTab, this);
    //     EventController.getInstance().addEventListener(EventController.SHOP_ITEM_SELECTED,this.onShopItem, this);
    //     this.add_unlock.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onAdd, this);
    //     this.reduce_unlock.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onReduce, this);
    //     this.max_unlock.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onMax, this);
    //     this.buy_unlock.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBuy, this);
    //     this.img_refresh.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRefresh, this);
    //     if( this.flag){
    //         this.shop_container.addChild(GuildMaterialShop.getInstance());
    //         if( this.fuck_tab.selectedIndex == 0){
    //             GuildMaterialShop.getInstance().setType(1);
    //             egret.setTimeout(GuildMaterialShop.getInstance().forceSelect, GuildMaterialShop.getInstance(),100);
    //         }else{
    //             GuildMaterialShop.getInstance().setType(2);
    //         }
    //     }
    // }
    // private onRemoved(evt:egret.Event){
    //     if( this.lastSelectItem)
    //         this.lastSelectItem.setState("normal");
    //     this.lastSelectItem = null;
    //     this.img_return.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onReturn, this);
    //     this.fuck_tab.removeEventListener(eui.IndexChangeEvent.CHANGE, this.onSelectedTab, this);
    //     EventController.getInstance().removeEventListener(EventController.SHOP_ITEM_SELECTED,this.onShopItem, this);
    //     this.add_unlock.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onAdd, this);
    //     this.reduce_unlock.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onReduce, this);
    //     this.max_unlock.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onMax, this);
    //     this.buy_unlock.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onBuy, this);
    //     this.img_refresh.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onRefresh, this);
    // }
    // private lastSelectItem:FuckItem;
    // private onShopItem(evt:egret.Event){
    //     if( this.lastSelectItem){
    //         this.lastSelectItem.setState("normal");
    //     }
    //     this.forceSelectItem(evt.data);
    // }
    // public forceSelectItem(item:FuckItem){
    //     this.lastSelectItem = item;
    //     this.lastSelectItem.setState("select");
    //     this.updateShopItemRelated(this.lastSelectItem.curData);
    // }
    // private updateShopItemRelated(data:GoodInfo){
    //     if( data == null || GuildMgr.getInstance().isShopGoodLocked(data.id) ){
    //         this.group_unlock.visible = true;
    //         this.group_lock.visible = this.group_pet_material.visible = false;
    //         if( data != null)
    //             this.updateUnlockGroup(data);
    //         else
    //             this.group_unlock.visible = false;
    //     }else{
    //         this.group_lock.visible = true;
    //         this.group_unlock.visible = this.group_pet_material.visible = false;
    //         this.updateLockGroup(data);
    //     }
    // }
    // public onBuyBack(){
    //     this.lab_unlock_2.text = GetNumString(GuildMgr.getInstance().myMemberInfo.contribution,false, true);
    // }
    // private updateUnlockGroup(data:GoodInfo){
    //     this.icon_unlock.source = GameConst.Res_Root + "resource/assets/items/" + data.id + ".png";
    //     this.lab_name_unlock.text = data.name;
    //     this.lab_unlock_2.text = GetNumString(GuildMgr.getInstance().myMemberInfo.contribution,false, true);
    //     this.lab_unlock.text = "20";
    //     this.lab_unlock_1.text = "消耗：贡献 " +this.lastSelectItem.curData.price*20;
    // }
    // private updateLockGroup(data:GoodInfo){
    //     this.icon_lock.source = GameConst.Res_Root + "resource/assets/items/" + data.id + ".png";
    //     this.lab_name_lock.text = data.name+"\r"+data.descs;
    //     this.lab_lock_2.text = GetNumString(GuildMgr.getInstance().myMemberInfo.contribution,false, true);
    // }
    // private nextAutoRefreshTime:number;
    // private updateMaterialGroup(){
    //     if( !FrameMgr.getInstance().isUnderControl(this.name)){
    //         this.nextAutoRefreshTime = GuildMgr.getInstance().myMemberInfo.lastShopRefreshTime + Model.EIGHT_HOUR;
    //         FrameMgr.getInstance().addControll(this.frameItem);
    //     }
    // }

    // public onRefreshBack(){
    //     this.nextAutoRefreshTime = GuildMgr.getInstance().myMemberInfo.lastShopRefreshTime + Model.EIGHT_HOUR;
    // }

    // public img_return:eui.Image;
    // public fuck_tab:eui.TabBar;
    // private shop_container:eui.Group;
    // private group_unlock:eui.Group;
    // private group_lock:eui.Group;
    // private group_pet_material:eui.Group;

    // private icon_unlock:eui.Image;
    // private add_unlock:eui.Image;
    // private reduce_unlock:eui.Image;
    // private max_unlock:eui.Image;
    // private buy_unlock:eui.Image;
    // private lab_unlock:eui.Label;
    // private lab_unlock_1:eui.Label;
    // private lab_name_unlock:eui.Label;
    // private lab_unlock_2:eui.BitmapLabel;

    // private icon_lock:eui.Image;
    // private lab_name_lock:eui.Label;
    // private lab_lock_2:eui.Label;

    // private img_refresh:eui.Image;
    // private refresh_timer:eui.Label;
    // private refresh_price:eui.Label;
    // public partAdded(name:string, instance:any) {
    //     super.partAdded(name, instance);
    //     if (name == "fuck_tab") {
    //         this.fuck_tab = instance;
    //         this.fuck_tab.itemRenderer = new eui.ClassFactory(GuildShopTab);
    //         this.fuck_tab.dataProvider = new eui.ArrayCollection([0,1]);
    //     }else if (name == "img_refresh") {
    //         this.img_refresh = instance;
    //     }else if (name == "refresh_timer") {
    //         this.refresh_timer = instance;
    //     }else if (name == "refresh_price") {
    //         this.refresh_price = instance;
    //     } else if (name == "lab_lock_2") {
    //         this.lab_lock_2 = instance;
    //     }else if (name == "icon_lock") {
    //         this.icon_lock = instance;
    //     }else if (name == "lab_name_lock") {
    //         this.lab_name_lock = instance;
    //     } else if (name == "shop_container") {
    //         this.shop_container = instance;
    //     }else if (name == "img_return") {
    //         this.img_return = instance;
    //     }else if (name == "lab_name_unlock") {
    //         this.lab_name_unlock = instance;
    //     }else if (name == "icon_unlock") {
    //         this.icon_unlock = instance;
    //     }else if (name == "add_unlock") {
    //         this.add_unlock = instance;
    //     }else if (name == "reduce_unlock") {
    //         this.reduce_unlock = instance;
    //     }else if (name == "max_unlock") {
    //         this.max_unlock = instance;
    //     }else if (name == "buy_unlock") {
    //         this.buy_unlock = instance;
    //     }else if (name == "lab_unlock") {
    //         this.lab_unlock = instance;
    //     }else if (name == "lab_unlock_1") {
    //         this.lab_unlock_1 = instance;
    //     } else if (name == "lab_unlock_2") {
    //         this.lab_unlock_2 = instance;
    //     }else if (name == "group_unlock") {
    //         this.group_unlock = instance;
    //     }else if (name == "group_lock") {
    //         this.group_lock = instance;
    //     }else if (name == "group_pet_material") {
    //         this.group_pet_material = instance;
    //     }
    // }
    // private flag;
    // public childrenCreated(){
    //     super.childrenCreated();
    //     this.shop_container.addChild(GuildMaterialShop.getInstance());
    //     GuildMaterialShop.getInstance().setType(1);
    //     this.flag = true;
    // }
    private static _instance:GuildShop;
    public static getInstance():GuildShop{
        if( GuildShop._instance == null)
            GuildShop._instance = new GuildShop();
        return GuildShop._instance;
    }
}